package com.kele.order.controller;

import com.kele.common.model.response.Result;
import com.kele.order.model.Cart;
import com.kele.order.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("cart")
public class CartController {


    @Autowired
    HttpServletRequest request;

    @Autowired
    CartService cartService;
    /**
     *
     * @param goodsId
     * @param num
     * @return
     */
    @GetMapping("addToCart/{goodsId}/{num}")
    public Result addToCart(@PathVariable Long goodsId, @PathVariable Integer num){

        //从Authorization 头信息里面获取 Bearer token
        String userid = request.getHeader("userid_1905A");
        return cartService.addToCart(userid,goodsId,num);
    }

    @GetMapping("getCart")
    public Cart getCart(){

        //从Authorization 头信息里面获取 Bearer token
        String userid = request.getHeader("userid_1905A");
        return cartService.getCart(userid);
    }
}


